package com.ruoyi.web.controller.depot;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.depot.domain.ProcuredStorageDetail;
import com.ruoyi.depot.domain.vo.DetailedInventoryAgeVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.depot.domain.ProcuredStorage;
import com.ruoyi.depot.service.IProcuredStorageService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 采购入库单Controller
 * 
 * @author ruoyi
 * @date 2023-12-13
 */
@RestController
@RequestMapping("/depot/ProcuredStorage")
public class ProcuredStorageController extends BaseController
{
    @Autowired
    private IProcuredStorageService procuredStorageService;

    /**
     * 查询采购入库单列表
     */
    @PreAuthorize("@ss.hasPermi('depot:ProcuredStorage:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProcuredStorage procuredStorage)
    {
        startPage();
        List<ProcuredStorage> list = procuredStorageService.selectProcuredStorageList(procuredStorage);
        return getDataTable(list);
    }

    /**
     * 导出采购入库单列表
     */
    @PreAuthorize("@ss.hasPermi('depot:ProcuredStorage:export')")
    @Log(title = "采购入库单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProcuredStorage procuredStorage)
    {
        List<ProcuredStorage> list = procuredStorageService.selectProcuredStorageList(procuredStorage);
        ExcelUtil<ProcuredStorage> util = new ExcelUtil<ProcuredStorage>(ProcuredStorage.class);
        util.exportExcel(response, list, "采购入库单数据");
    }

    /**
     * 获取采购入库单详细信息
     */
    @PreAuthorize("@ss.hasPermi('depot:ProcuredStorage:query')")
    @GetMapping(value = "/{storageId}")
    public AjaxResult getInfo(@PathVariable("storageId") Long storageId)
    {
        return success(procuredStorageService.selectProcuredStorageByStorageId(storageId));
    }

//    /**
//     * 新增采购入库单
//     */
//    @PreAuthorize("@ss.hasPermi('depot:ProcuredStorage:add')")
//    @Log(title = "采购入库单", businessType = BusinessType.INSERT)
//    @PostMapping
//    public AjaxResult add(@RequestBody ProcuredStorage procuredStorage)
//    {
//        return toAjax(procuredStorageService.insertProcuredStorage(procuredStorage));
//    }

    /**
     * 修改采购入库单
     */
    @PreAuthorize("@ss.hasPermi('depot:ProcuredStorage:edit')")
    @Log(title = "采购入库单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProcuredStorage procuredStorage)
    {
        return toAjax(procuredStorageService.updateProcuredStorage(procuredStorage));
    }

    /**
     * 删除采购入库单
     */
    @PreAuthorize("@ss.hasPermi('depot:ProcuredStorage:remove')")
    @Log(title = "采购入库单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{storageIds}")
    public AjaxResult remove(@PathVariable Long[] storageIds)
    {
        return toAjax(procuredStorageService.deleteProcuredStorageByStorageIds(storageIds));
    }

    @PreAuthorize("@ss.hasPermi('depot:ProcuredStorage:query')")
    @GetMapping(value = "/product/getStockAgeDetails")
    public TableDataInfo getDetailedInventoryAge(DetailedInventoryAgeVO vo)
    {
        startPage();
        return getDataTable(procuredStorageService.getDetailedInventoryAge(vo));
    }
}
